package edu.zut.software.identity.Service.impl;

import edu.zut.software.identity.Repository.TeaCollegeRepository;
import edu.zut.software.identity.Repository.TeacherRepository;
import edu.zut.software.identity.Service.TeaCollegeService;
import edu.zut.software.identity.domain.StuMajor;
import edu.zut.software.identity.domain.TeaCollege;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeaCollegeServiceImpl implements TeaCollegeService {
    private TeaCollegeRepository teaCollegeRepository;
    @Autowired
    public void setTeaCollegeRepository(TeaCollegeRepository teaCollegeRepository) {
        this.teaCollegeRepository = teaCollegeRepository;
    }


    @Override
    public TeaCollege findById(String id) {
        return teaCollegeRepository.findById(id).orElseThrow(RuntimeException::new);
    }

    @Override
    public List<TeaCollege> findAll() {
        return teaCollegeRepository.findAll();
    }

    @Override
    public void deleteById(String id) {
        teaCollegeRepository.deleteById(id);
    }

    @Override
    public void save(TeaCollege teaCollege) {
        teaCollegeRepository.save(teaCollege);
    }

    /**
     *
     * @param collegeId 子部门指向的父部门的实际id
     * @return 返回父部门的wx_id
     */
    @Override
    public int getId(String collegeId) {
        return teaCollegeRepository.findById(collegeId).orElseThrow(RuntimeException::new).getWxId();
    }
    @Override
    public Page<TeaCollege> findAll(Integer page, Integer pageSize) {
        Pageable pageable = PageRequest.of(page, pageSize);
        return teaCollegeRepository.findAll(pageable);
    }

    @Override
    public boolean isExists(String id) {
        return teaCollegeRepository.existsById(id);
    }
}
